package com.tanhua.server.controller;

import com.tanhua.model.domain.Settings;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.model.vo.VisitorsVo;
import com.tanhua.server.service.MovementService;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author LiKe
 * @date 2022/1/22 10:48
 */
@RestController
@RequestMapping("/users")
public class SettingsController {

    @Autowired
    private SettingsService settingsService;



    /**
     * 获取用户通用设置
     * @return
     */
    @GetMapping("/settings")
    public ResponseEntity settings(){
        SettingsVo vo = settingsService.settings();
        return ResponseEntity.ok(vo);
    }

    /**
     * 更新问题
     * @param map
     * @return
     */
    @PostMapping("/questions")
    public ResponseEntity updateQuestions(@RequestBody Map map){
        String content = (String) map.get("content");
        settingsService.saveQuestion(content);
        return ResponseEntity.ok(null);
    }

    /**
     * 更新设置
     * @param settings
     * @return
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity updateSetting(@RequestBody Settings settings){

        settingsService.saveSetting(settings);

        return ResponseEntity.ok(null);
    }

    /**
     * 分页黑名单
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        //1、调用service查询
        PageResult pr = settingsService.blacklist(page,size);
        //2、构造返回
        return ResponseEntity.ok(pr);
    }

    /**
     * 取消黑名单
     * @param uid
     * @return
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackById(@PathVariable("uid") Long uid){

        settingsService.deleteBlackById(uid);

        return ResponseEntity.ok(null);
    }

}
